package com.heima.article.controller.v1;

import com.heima.article.service.IArticleService;
import com.heima.model.article.dtos.ArticleHomeDto;
import com.heima.model.common.dtos.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 加载文章列表接口
 */
@RestController
@RequestMapping("/api/v1/article")
public class ArticleHomeController {

    @Autowired
    private IArticleService articleService;

    /**
     * 首页加载,执行的就是推荐，查询所有
     * @param dto
     * @return
     */
    @PostMapping("/load")
    public ResponseResult load(@RequestBody ArticleHomeDto dto) {
        //return articleService.loadArticleList(dto,3L);
        return articleService.loadArticleList2(dto);
    }

    /**
     * 加载更多，type=1表示下拉最新，type=2表示上拉最多
     * @param dto
     * @return
     */
    @PostMapping("/loadmore")
    public ResponseResult loadMore(@RequestBody ArticleHomeDto dto) {
        return articleService.loadArticleList(dto,2L);
    }

    /**
     * 加载更新，下type=1表示下拉最新，type=2表示上拉最多
     * @param dto
     * @return
     */
    @PostMapping("/loadnew")
    public ResponseResult loadNew(@RequestBody ArticleHomeDto dto) {
        return articleService.loadArticleList(dto,1L);
    }
}